package org.bees.cms.core.furnish;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import org.bees.cms.common.Tree;
import org.bees.cms.core.Describable;
import org.bees.cms.core.Domain;
import org.bees.cms.core.Named;

@Entity
public class Kind extends Domain implements Named, Describable, Tree<Kind> {
	private static final long serialVersionUID = 5316597302610844046L;

	private String name;
	private String description;
	private Kind parent;
	private Set<Kind> children = new HashSet<Kind>();
	private Set<Product> products = new HashSet<Product>();
	private Set<Business> businesses = new HashSet<Business>();

	@Override
	public List<Kind> ancestors() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Kind> descendants() {
		// TODO Auto-generated method stub
		return null;
	}

	@Column(length = 24, nullable = false, unique = true)
	@Override
	public String getName() {
		return name;
	}

	@Override
	public void setName(String name) {
		this.name = name;
	}

	@Column(length = 120)
	@Override
	public String getDescription() {
		return description;
	}

	@Override
	public void setDescription(String description) {
		this.description = description;
	}

	@ManyToOne(cascade = { CascadeType.REFRESH })
	@Override
	public Kind getParent() {
		return parent;
	}

	@Override
	public void setParent(Kind parent) {
		this.parent = parent;
	}

	@OneToMany(cascade = { CascadeType.REMOVE }, mappedBy = "parent")
	@Override
	public Set<Kind> getChildren() {
		return children;
	}

	@Override
	public void setChildren(Set<Kind> children) {
		this.children = children;
	}

	@OneToMany(cascade = { CascadeType.REMOVE, CascadeType.REFRESH }, mappedBy = "kind")
	public Set<Product> getProducts() {
		return products;
	}

	public void setProducts(Set<Product> products) {
		this.products = products;
	}

	@OneToMany(cascade = { CascadeType.REMOVE, CascadeType.REFRESH }, mappedBy = "kind")
	public Set<Business> getBusinesses() {
		return businesses;
	}

	public void setBusinesses(Set<Business> businesses) {
		this.businesses = businesses;
	}

}
